﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using RemoteServer.Framework.Exceptions;
using RemoteServer.Framework.Method;

namespace RemoteServer.Framework.ApplicationServer
{
    class RemoteServerRequest
    {
        private HttpRequest _request;
        public RemoteServerRequest(HttpRequest request)
        {
            this._request = request;
        }

        #region Methods
        public RequestErrorEnum ProceedRequest()
        {
            RequestErrorEnum result = RequestErrorEnum.None;

            try 
            {
                this.Validate();

            }
            catch(BaseException ex)
            {
                return ex.RequestError;
            }

            return result;
        }

        private void Validate()
        {
            string _methodName = this._request.Params[Constants.METHOD_NAME].ToString();
            string _parameters = this._request.Params[Constants.PARAMETERS].ToString();
            string[] arrParams = _parameters.Split(Constants.PARAMETERS_DELIMITER);
            string _auth_key = this._request.Params[Constants.AUTH_KEY].ToString();
            string _viewer_id = this._request.Params[Constants.VIEWER_ID].ToString();

            if (Utils.CheckMD5(_auth_key, _viewer_id))
            {
                throw new BadAuthKeyOrViewerIDException();
            }

        }
        #endregion

        internal MethodBase GetMethod()
        {
            throw new NotImplementedException();
        }
    }
}
